package com.ebookstore.service.impl;

import java.util.List;

import com.ebookstore.dao.BaseDAO;
import com.ebookstore.dto.Book;
import com.ebookstore.dto.Item;
import com.ebookstore.exception.EBookStoreException;
import com.ebookstore.service.CartService;

public class CartServiceImpl implements CartService {
  private BaseDAO bookDao = new BaseDAO();

  public CartServiceImpl() {
    super();
  }

  /**
   * <p>
   * 方法实现的功能 : 向购物车中加入一本书
   * </p>
   * 
   * @param book
   * @throws EBookStoreException
   */
  public void addBookToCart(Book book) {
    try {
      bookDao.addObject(book);
    }
    catch (EBookStoreException e) {
      e.printStackTrace();
    }
  }

  /**
   * <p>
   * 方法实现的功能 : 从购物车中移去一本书
   * </p>
   * 
   * @param book
   * @throws EBookStoreException
   */
  public void removeBookFromCart(Book book) {
    try {
      bookDao.deleteObject(book);
    }
    catch (EBookStoreException e) {
      e.printStackTrace();
    }
  }

  /**
   * <p>
   * 方法实现的功能 : 列出购物车中已有的书
   * </p>
   * 
   * @param strsql
   * @return
   */
  public List findBooksInCart(String strsql) {
    return bookDao.findByHql(strsql);
  }
  
  public Item findItemById( int id ){
	  Item item = (Item) bookDao.findById(id, Item.class);//非空
//	  System.out.println("CartService.findItemById():item id="+item.getItemId());
	  return item;
  }
  

}
